const webpack = require('webpack')
const { RawSource } = webpack.sources

class Plugin1 {
  apply(compiler) {
    compiler.hooks.thisCompilation.tap('Plugin1', (compilation) => {
      compilation.hooks.additionalAssets.tapAsync('Plugin1', (callback) => {
        const content = 'i love you'
        compilation.assets['a.txt'] = {
          // 文件大小
          size() {
            return content.length
          },
          // 文件内容
          source() {
            return content
          }
        }

        compilation.assets['b.txt'] = new RawSource(content)
        callback()
      })
    })
  }
}

module.exports = Plugin1
